import requests
host = "https://mall.deyunce.com/"
def login(zhi_1,zhi_2,zhi_3):
    api_account_login = "api/account/login"
    url = host+api_account_login
    headers = {
        "Content-Type": "application/json",
        "Authorization": "Basic ZGV5dW5jZTo4MjgxMjM="
    }
    json_data = {
        "account": zhi_1,
        "password": zhi_2,
        "client": zhi_3
    }
    # requests = requests.post(url, json=json_data, headers=headers)
    # resbody = requests.json()
    # res_msg = resbody["msg"]
    # res_code = requests.status_code
    # res_name = resbody["data"]["nickname"]
    # print("响应码：", res_msg)
    # print("响应文本:", requests.text)
    # print("响应结果", res_msg)
    # assert res_code == 200
    # assert res_msg == "登录成功"
    # assert res_name == "62期唐浩洋"
    response = requests.post(url, json=json_data, headers=headers)
    return response
# if __name__ == '__main__':
#     response = login("19710079687","18103945931t",5)
#     res_code = response.status_code
#     resbody = response.json()
#     res_token = resbody["data"]["token"]
#     print(res_code)
#     print(res_token)
def uer_account_log(token,source,type=None):
    api_uer_account_log = 'api/user/accountlog'
    url = host+api_uer_account_log
    headers = {
        "Content-Type": "application/json",
        "Authorization": "Basic ZGV5dW5jZTo4MjgxMjM=",
        "Token": token
    }
    params = {
        "source": source,
        "type": type
    }
    response = requests.get(url=url, params=params, headers=headers)
    return response
def cart_change(token,cart_id,goods_num):
    # api地址
    api_cart_change = 'api/cart/change'
    # url地址
    url = host+api_cart_change
    # 请求头
    headers = {
        "Content-Type": "application/json",
        "Authorization": "Basic ZGV5dW5jZTo4MjgxMjM=",
        "Token": token
    }
    # 参数
    json_data ={
        "cart_id": cart_id,
        "goods_num": goods_num
    }
    # 发送请求
    reponse = requests.post(url=url,json=json_data,headers=headers)
    return  reponse
if __name__ == '__main__':
    login_res = login("19710079687","18103945931t",5)
    login_resbody = login_res.json()
    token = login_resbody["data"]["token"]
    # 获取明细
    uer_accont_log_res = uer_account_log(token,1)
    uer_accont_log_res_resbody = uer_accont_log_res.json()
    print(uer_accont_log_res_resbody["msg"])
    # 改变购物车数量为2
    cart_change_res = cart_change(token, 10225, 2)
    cart_change_resbody = cart_change_res.json()
    print(cart_change_resbody)
